package com.ruoyi.web.domain.warning;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.text.Collator;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 因子管理表
 * @author fwx
 * @since 2024-01-30 15:02:56
 */
@Data
//@TableName("tt_wq_factor_info")
@TableName("standard_property")
@ApiModel(value = "FactorInfo对象", description = "因子管理表")
public class FactorInfo implements Serializable,Comparable<FactorInfo> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("因子类型")
    @TableField("factor_type")
    private String factorType;

    @ApiModelProperty("因子名称")
//    @TableField("factor_name")
    @TableField("standard_name")
    private String factorName;

    @ApiModelProperty("因子key")
//    @TableField("factor_key")
    @TableField("standard_id")
    private String factorKey;

    @ApiModelProperty("因子单位")
//    @TableField("factor_unit")
    @TableField("unit")
    private String factorUnit;


    @ApiModelProperty("统计项")
    @TableField("count_item")
    private String countItem;

    @ApiModelProperty("描述")
    @TableField("description")
    private String description;

    @ApiModelProperty("数据类型")
//    @TableField("data_types")
    @TableField(exist = false)
    private String dataTypes;

    @ApiModelProperty("枚举类型的映射值")
//    @TableField("data_enum")
    @TableField(exist = false)
    private String dataEnum;

    @ApiModelProperty("量程开始值")
    @TableField("range_begin")
    private Integer rangeBegin;

    @ApiModelProperty("量程结束值")
    @TableField("range_end")
    private Integer rangeEnd;

    @ApiModelProperty("创建时间")
    @TableField("crt_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime crtTime;

    public Set<String> buildCountItem(){

        if(countItem == null){
            return new HashSet<>();
        }

        Set<String> collectItem = Arrays.stream(countItem.split(",")).collect(Collectors.toSet());
        return collectItem;
    }

    static Collator collator = Collator.getInstance(Locale.CHINA);

    @Override
    public int compareTo(FactorInfo factorInfo) {
        if(factorInfo == null){
            return 0;
        }

        return collator.reversed().compare(factorInfo.getFactorName(),this.getFactorName());
    }

}
